package com.tengol.course.spring.boot.database.jdbc.common;

import com.tengol.course.spring.boot.database.jdbc.entity.User;
import org.springframework.jdbc.core.RowMapper;

import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * UserMapRow
 *
 * @author dongrui
 * @date 2020/05/30
 */
public class UserRowMapper implements RowMapper<User> {
    @Override
    public User mapRow(ResultSet rs, int rowNum) throws SQLException {
        int id = rs.getInt("id");
        String userName = rs.getString("user_name");
        String password = rs.getString("password");

        return User.builder().id(id).userName(userName).password(password).build();
    }
}
